package com.jack.configuration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.jack.entity.User;
import com.jack.service.UserFeignClient;

import feign.hystrix.FallbackFactory;

@Component
public class FeignClientFallbackFactory implements FallbackFactory<UserFeignClient> {

	private static final Logger logger = LoggerFactory.getLogger(FeignClientFallbackFactory.class);
	
	@Override
	public UserFeignClient create(Throwable cause) {
		UserFeignClient userFeignClient = new UserFeignClient() {
			
			@Override
			public User findById(Long id) {
				logger.info("fall back: reason", cause );
				User user = new User();
				user.setId(-1L);
				user.setName("default name");
				return user;
			}
		};
				
		return userFeignClient;
	}

}
